package com.swallow.auth.domain.tenant.service.impl;

import com.swallow.auth.common.result.R;
import com.swallow.auth.common.result.Result;
import com.swallow.auth.domain.tenant.model.TenantEntity;
import com.swallow.auth.domain.tenant.model.TenantRoot;
import com.swallow.auth.domain.tenant.service.ITenantDomainService;
import com.swallow.auth.domain.uniqno.NumWorker;
import com.swallow.auth.domain.uniqno.model.entity.BizNoValObj;
import org.springframework.stereotype.Service;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-11 21:39:21
 * @version: v1.0
 * @describe: class responsibility
 */
@Service
public class TenantDomainServiceImpl implements ITenantDomainService {

    @Override
    public Result<String> createTenant(TenantRoot tenantRoot) {
        TenantEntity tenantEntity = tenantRoot.getTenantEntity();
        // 唯一标识
        tenantEntity.setTenantNo(NumWorker.bizNo(BizNoValObj.TENANT_NO));
        // 重复性校验
        tenantEntity.repeatCheck();
        // 结果保存
        tenantEntity.create();

        return R.success(tenantEntity.getTenantNo());
    }
}
